	//qq，微信登录
	var auths={};
	mui.plusReady(function() {
		// 获取登录认证通道
		plus.oauth.getServices(function(services){
			var txt="登录认证通道：";
			for(var i in services){
				var service=services[i];
				console.log(service.id+": "+service.authResult+", "+service.userInfo);
				auths[service.id]=service;
				txt += "id:"+service.id+", ";
				txt += "description:"+service.description+", ";
			}
			console.log(txt)
		},function(e){
			outLine("获取登录认证失败："+e.message);
		});
	})
	
	// 登录认证
	function login(id){
		console.log("----- 登录认证 -----");
		var auth=auths[id];
		if(auth){
			var w=null;
			if(plus.os.name=="Android"){
				w=plus.nativeUI.showWaiting();
			}
			document.addEventListener("pause",function(){
				setTimeout(function(){
					w&&w.close();w=null;
				},2000);
			}, false );
			auth.login(function(){
				w&&w.close();w=null;			
				console.log("登录认证成功：");
				console.log(JSON.stringify(auth.authResult));
				userinfo(auth,id);
			},function(e){
				w&&w.close();w=null;
				console.log("登录认证失败：");
				console.log("["+e.code+"]："+e.message);
				plus.nativeUI.alert("授权登录失败：错误信息["+e.code+"]",null,"登录失败")
				//plus.nativeUI.alert("详情错误信息请参考授权登录(OAuth)规范文档：http://www.html5plus.org/#specification#/specification/OAuth.html",null,"登录失败["+e.code+"]："+e.message);
			});
		}else{
			console.log("无效的登录认证通道！");
			plus.nativeUI.alert("无效的登录认证通道！",null,"登录失败");
		}
	}

	// 获取用户信息
	function userinfo(a,id){
		var req_login = {};
		a.getUserInfo(function(){
			//qq,weixin
			req_login.open_id = a.authResult.openid || a.userInfo.openid;
			req_login.nick_name = a.userInfo.nickname;
			var sex = a.userInfo.gender||a.userInfo.sex;
			if (sex == "男" || sex == 1){
				req_login.sex = 1
			}else{
				req_login.sex = 2
			} 
			req_login.province = a.userInfo.province
			req_login.city = a.userInfo.city
			req_login.country = a.userInfo.country||"";
			req_login.headimg_url = a.userInfo.figureurl_qq_2||a.userInfo.headimgurl;
			req_login.type = id;
			
			require(["login","getui"],function(login,getui){
				login.OnThirdLogin(req_login,function(){//成功回调
					getui.OnBindUser();//绑定user
					console.log("登录成功")
					OnOpenWindow("../main.html","main.html")
					OnDestroy(null);	
				},function(){//未绑定回调
					OnOpenWindow("../bind/get_photo.html","get_photo.html",{open_id:req_login.open_id,type:id})
					OnDestroy(null);
				});
			});
			
//			console.log("获取用户信息成功：");
//			console.log(JSON.stringify(a.userInfo));
//			console.log(JSON.stringify(req_login));
//			plus.nativeUI.toast("欢迎“"+req_login.nick_name+"”");
		},function(e){
			console.log("获取用户信息失败：");
			console.log("["+e.code+"]："+e.message);
			plus.nativeUI.toast("获取用户信息失败！");
		});
	}
	
	// 注销登录
	function logoutAll(){
		outSet("----- 注销登录认证 -----");
		for(var i in auths){
			logout(auths[i]);
		}
	}
	function logout(auth){
		auth.logout(function(){
			console.log("注销\""+auth.description+"\"成功");
		},function(e){
			console.log("注销\""+auth.description+"\"失败："+e.message);
		});
	}
